package com.dubito.concurrency.example.singleton;

import com.dubito.concurrency.annotation.NoRecommend;
import com.dubito.concurrency.annotation.ThreadSafe;

/**
 * @author liliang
 * @description: 懒汉模式 不推荐 synchro
 * @date 2018/6/24.
 */
@ThreadSafe
@NoRecommend
public class SingletonExample3 {

    /**
     *  私有构造
     */
    private SingletonExample3(){}

    /**
     * 单例对象
     */
    private static SingletonExample3 instance = null;

    /**
     * 静态的工厂方法
     * @return
     */
    public static synchronized SingletonExample3 getInstance () {
        if (instance == null) {
            instance = new SingletonExample3();
        }
        return instance;
    }
}
